<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2018/6/22
 * Time: 下午9:40
 */

namespace frontend\controllers;


use yii\web\Controller;
use common\models\Photoes;

class PictureController extends Controller {

	public function beforeAction($action){
		return true;
	}

	public function actionIndex(){
		$model = new Photoes;

		return $this->render('index',['model'=>$model]);
	}

	public function actionUpdate(){
		$model = new Photoes;
		if (\Yii::$app->request->isPost){
			$post = \Yii::$app->request->post();
			$model->updateImage($post);
		}

		return $this->render('update',['model'=>$model]);
	}

	public function actionHotphotoes(){
		$model = new Photoes;

		return $this->render('hotphotoes',['model'=>$model]);
	}

	public function actionMyphotoes(){
		$model = new Photoes;

		return $this->render('myphotoes',['model'=>$model]);
	}

	public function actionFellowphotoes(){
		$model = new Photoes;

		return $this->render('fellowphotoes',['model'=>$model]);
	}

	public function actionLike(){
		$model = new Photoes;
		$likeRecord = new Likes;
		if (\Yii::$app->request->isPost){
			$post = \Yii::$app->request->post();
			$model = Photoes::findOne(['id'=>$post['id']]);
			$model->likes = $post['like'];
			if ($model->save(false)&&$likeRecord->like($post['id'],$post['uid'])){
				return true;
			}
		}
		return false;
	}
}